package task.threads;

public class ThreadJoinMethod {

    public static void main(String[] args) throws InterruptedException {

        long start=System.currentTimeMillis();

        // 在这里创建一个线程或线程池，
        final int[] result = {0};
        Thread thread = new Thread(){

            @Override
            public void run() {
                result[0] = sum();
            }
        };
        // 异步执行 下面方法
        thread.start();
        thread.join();


        // 确保  拿到result 并输出
        System.out.println("异步计算结果为："+ result[0]);

        System.out.println("使用时间："+ (System.currentTimeMillis()-start) + " ms");

        // 然后退出main线程
    }

    private static int sum() {
        return fibo(36);
    }

    private static int fibo(int a) {
        if ( a < 2)
            return 1;
        return fibo(a-1) + fibo(a-2);
    }
}
